<?php


namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use App\library\services\UserConsumeService;
use App\library\services\WxUserService;
use App\Models\WxUser;
use Illuminate\Http\Request;

class WxUserController extends Controller
{
    /**
     * Author:YangXinPeng
     * 获取微信用户信息
     * @param Request $request
     * @return mixed
     */
    public function getUser(Request $request)
    {
       $id = $request->get('id');
       if (!is_numeric($id)){
          return $this->fail('参数错误');
       }
       $res = WxUserService::getWxUser($id);
       return $this->success('成功',$res);
    }

    /**
     * Author:YangXinPeng
     * 解密获取用户ID
     * @param Request $request
     * @return mixed
     */
    public function getId(Request $request)
    {
       $secret = $request->get('secret');
       if (empty($secret)){
           return $this->fail('参数错误');
       }
       $id = decrypt($secret);
       $data = ['id'=>$id];
       return $this->success('成功',$data);
    }

    /**
     * Author:Zhongyuan Lu
     * 用户消费记录列表
     * @param Request $request
     * @return mixed
     */
    public function getUserConsumeList(Request $request)
    {
        $time = $request->get('time','');
        $uid = $request->uid;

        if (empty($time)) {
            $time = date('Y-m',time());
        }

        $data = UserConsumeService::getUserConsumeList($uid, $time);
        return $this->res($data);
    }

    public function sign(Request $request)
    {
        $uid = $request->uid;
        $params = [];
        $params['uid'] = $uid;
        $params['searchtime'] = $request->get('searchtime');
        WxUserService::sign($params);
    }


}
